
<template>
  <div id="app" class="login-container">
    <div class="login-form">
      <h2 style="margin-bottom: 50px; color:gray">修改密码</h2>
      <div class="form-group">
        <input type="password" id="password" v-model="form.password1" placeholder="请输入新密码" required="required" />
      </div>
      <div class="form-group">
        <input type="password" id="password" v-model="form.password2" placeholder="请确认新密码" required="required" />
      </div>
      <el-button type="primary" @click="updatepassword()" class="dl">修改</el-button>
    </div>

  </div>
</template>

<style scoped>
.dl{
  margin-top: 5px;
}
span{
  color:gray;
  font-size: 14px;
}
input{
  border-radius: 4px;
}
#app {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #158eec; /* 蓝色背景 */
}

.login-form {
  background-color: white;
  padding: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  width: 300px;
  height: 300px;
  margin-left: 500px;

  border-radius: 4px
}


label {
  display: block;
  margin-bottom: 5px;
}

input {
  width: 100%;
  padding: 8px;
  box-sizing: border-box;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

.login-form {
  max-width: 300px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  text-align: center;
}

input {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 10px;
  box-sizing: border-box;
}

.captcha-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.captcha {
  cursor: pointer;
  font-size: 16px;
  color: blue;
  user-select: none;
}

button {
  display: block;
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}


</style>

<script>
export default {
  data() {
    return {
      user:{},
      form:{},
    };
  },
  methods: {
    updatepassword(){
      if (this.form.password1==null || this.form.password1==''){
        this.$message.error('请填写新密码');
        return;
      }
      if (this.form.password2==null || this.form.password2==''){
        this.$message.error('请填写确认密码');
        return;
      }
      if (this.form.password1!=this.form.password2){
        this.$message.error('两次密码不一致');
      }
      this.axios.post(`http://localhost:9009/user/updatePassword?id=${this.user.id}&password=${this.form.password1}`).then(res=>{
        if (res.data.code==200){
          this.$message.success("修改成功");
          location.href="#/showye";
        }else{
          this.$message.error("修改失败");
        }
      })
    }
  },
  created() {
    this.user=JSON.parse(sessionStorage.getItem('userDB'));
  },
};
</script>
